<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {



  function __construct()
  {
  	parent::__construct();
	$this->load->Model("Muser");
	session_start();
	load_lang("admin");
	
  }
  function index()
  {
  	if(isset($_POST["submit"]))
  	{
  		
			
		if($_POST["username"] == "")
			$data["error"]=$this->lang->line('user_error');//"Please enter your username.";
		else
			$username= $this->input->post("username");
		if($_POST["password"] == "")
			$data["error"]=$this->lang->line('pass_error');//"Please enter your password.";
		else
			$password= $this->input->post("password");	
			
		
		if(isset($username) && isset($password))
		{
			$checklogin = $this->Muser->check_user(remove_string($username) ,$password);	
			
			
			
				
			if ( $checklogin == FALSE)

				{	

					$data['error'] =$this->lang->line('login_error');		

				}else 
				{
					$this->load->model("Mpermission");
					//$a = $this->Mpermission->get_module_from_lvl($checklogin[0]['user_level']);
					//echo $a;
					
					$data_sess=array(

								 "admin_name"=>$checklogin[0]['user_member'],
								"admin_username" => $checklogin[0]['user_name'],
								"admin_email" => $checklogin[0]['user_email'],
								 "level" =>$checklogin[0]['user_level'],
						//		 "module" => $a ,

								 );
			//print_r($data_sess);

					$this->session->set_userdata($data_sess);
	// print_r($checklogin);
	// print_r($data_sess);
	//echo $a=$_SESSION["level"];
	
					redirect( 'admin/welcome', 'refresh');

				}
		}
	
		$this->load->view('admin/login',$data);
  		
	}
	else
		$this->load->view('admin/login',$data="");
	
  
  }
  
	function logout() {

		$this->session->unset_userdata('admin_username');
		$this->session->unset_userdata('email');
		$this->session->unset_userdata('level');

		//echo '<meta http-equiv="refresh" content="0;URL='.admin_link('login').'" />';

		redirect('admin/login', 'refresh');

	}

  }
 ?>